import React from 'react';
import { Breadcrumb,  Button,message} from 'antd';
import { hashHistory} from 'react-router';
import './indexDoctor.less';
import $ from 'jquery';
import Config from '../../common/config';
const config = new Config();
const token = sessionStorage.getItem('token');
const arr=[1,2,3];
export default class IndexDoctor extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            bannerList: [],
            BannerId: undefined,
        }
    }
    componentDidMount() {
        this.getBannerList();
    }
    //获取列表
    getBannerList() {
        $.ajax({
            url: `${config.integratedBack2}/inte/findQdList`,
            type: "get",
            async: true,
            headers: {
                'Authorization': 'Bearer ' + token,
            },
            data:{
                qdxsNum:1,
            },
            success: res => {
                console.log(res);
                if (res.code === 200) {
                    const bannerList = res.qdList;
                    if (bannerList.length > 0) {
                        bannerList.forEach((ele, i) => {
                            ele.index = i + 1;
                        });
                        this.setState({
                            bannerList,
                        });
                    } else {
                        this.setState({
                            bannerList,
                        });
                    }
                }
            }
        });
    }
    //同步到前端
    uploadToFront(){
        $.ajax({
            url: `${config.integratedBack2}/inte/docSyncFront `,
            type: "get",
            async: true,
            headers: {
                'Authorization': 'Bearer ' + token,
            },
            success: res => {
                if (res.code === 200) {
                    message.success('同步成功!',1);
                }else{
                    message.error(data.msg,1);
                }
            }
        });
    }
    render() {
        let {bannerList}=this.state;
        return (
            <div className="index-doctor goods-label-cont" style={{background: '#f5f5f5'}} >
                <div className="goods-label-cont clearfix" style={{minHeight:0,}}>
                    <div className='goods-label-cont-nav clearfix'>
                        <Breadcrumb separator=">">
                            <Breadcrumb.Item>综合平台</Breadcrumb.Item>
                            <Breadcrumb.Item><span className='separator-a'>首页名医在线</span></Breadcrumb.Item>
                        </Breadcrumb>
                    </div>
                    <div className='spgl2-2 clearfix'>
                        <div className='member-content-Search'>
                            <Button className='member-button ' onClick={this.uploadToFront.bind(this)} >同步到前端</Button>
                        </div>
                    </div>
                </div>
                <div className="doctor-content">
                    <ul className="index-doctor-content" style={{width:(300*arr.length)+'px'}}>
                        {bannerList.length?
                            bannerList.map((item,i)=> <li key={i}>
                                <div><img src={item.headUrl?item.headUrl:''} alt=""/></div>
                                <b>{item.name}&nbsp;{item.job}</b>
                                <p>{item.goodAt}</p>
                                <Button type="primary" onClick={()=>{hashHistory.push({pathname:'chooseIndexDoctor',state:item.id})}}>编辑</Button>
                            </li>):
                            arr.map((item,i)=>
                                <li key={i} style={{marginBottom:'50px'}}>
                                    <b style={{marginTop:'120px',color:'#aaa',fontSize:'16px'}}>未选择医生或医师</b>
                                   <Button type="primary" style={{marginTop:'70px'}} onClick={()=>{hashHistory.push({pathname:'chooseIndexDoctor',state:0})}}>编辑</Button>
                                </li>)
                        }
                    </ul>
                </div>
            </div>
        )
    }
}